﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using IBMS.Common;

namespace IBMS.Page
{
    public partial class PasswordModify : System.Web.UI.Page
    {
        private User user = new User();
        private DB db = new DB();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                this.Label2.Visible = false;
                if (Session["User"] != null)
                {
                    user=(User)Session["user"];
                    this.name.Text = user.Name;
                }
            }
        }

        protected void btn_save_Click(object sender, EventArgs e)
        {
            if (IsValid)
            {
                if (Session["User"] != null)
                {
                    user = (User)Session["user"];
                }
                if (!user.Password.Equals(user.MD5(this.password.Text.ToString())))
                {
                    this.Label2.Visible = true;
                }
                else
                {
                    User temuser = new User();
                    temuser.Name = this.name.Text.ToString();
                    temuser.Password = temuser.MD5(this.newPassword1.Text.ToString());
                    bool result = db.ExecuteNonQury("update Users set Password='" + temuser.Password + "' where ID=" + user.Id);
                    if (result)
                        System.Web.UI.ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "", "alert('修改成功'); window.close()", true);
                    else
                        System.Web.UI.ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "", "alert('失败'); window.close()", true);
                }

                
            }
        }
    }
}